package com.example.smart.ui.activity.home

import com.example.lib.extend.setOnDoubleClickListener
import com.example.lib.utils.TimeUtils
import com.example.lib.utils.statusbar.StatusBarUtils
import com.example.smart.R
import com.example.smart.base.ui.activity.BaseActivity
import com.example.smart.databinding.ActivityYsBinding
import com.example.smart.dialog.AddressDialog
import com.example.smart.dialog.DateDialog
import com.example.smart.dialog.YsSuccessDialog

class YsActivity : BaseActivity<ActivityYsBinding>() {
    private var type = 0
    private val mAddressDialog by lazy {
        AddressDialog(this@YsActivity).also { dialog ->
            dialog.onResult2 = { result, result2 ->
                if (type == 0) {
                    binding.From1.text = result2
                    binding.From2.text = result
                } else {
                    binding.To1.text = result2
                    binding.To2.text = result
                }
            }
        }
    }

    private val mYsDialog by lazy {
        YsSuccessDialog(this@YsActivity)
    }

    private val mDateDialog by lazy {
        DateDialog(this@YsActivity)
    }

    override fun layoutID() = R.layout.activity_ys

    override fun initView() {
        StatusBarUtils.setStateAndNavigationBar(this@YsActivity, statusBarColor = com.example.lib.R.color.black_ececf8)
        binding.Radio1.isChecked = true
        binding.DateText.text = TimeUtils.formatTime(System.currentTimeMillis(), "yyyy年MM月")
    }

    override fun initListener() {
        binding.From.setOnDoubleClickListener {
            type = 0
            mAddressDialog.show()
        }

        binding.To.setOnDoubleClickListener {
            type = 1
            mAddressDialog.show()
        }

        binding.Radio2.setOnDoubleClickListener {
            mDateDialog.show(0)
        }

        binding.Date.setOnDoubleClickListener {
            mDateDialog.show(0)
        }

        mDateDialog.onResult = { type, result ->
            binding.DateText.text = result
        }

        binding.Confirm.setOnDoubleClickListener {
            mYsDialog.show()
        }

    }


}